﻿using System.Collections.Generic;
using System.Text;

namespace Safebrowsing
{
    /// <summary>
    /// Data request parameters
    /// </summary>
    public class DataRequest
    {
        /// <summary>
        /// Creates an empty instance of the DataRequest
        /// </summary>
        public DataRequest()
        {
            DataListRequests = new List<DataListRequest>();
        }

        public void AddDataListRequest(SafebrowsingList safebrowsingList, IEnumerable<int> addChunksNumbers, IEnumerable<int> subChunksNumbers)
        {
            DataListRequests.Add(new DataListRequest(safebrowsingList, addChunksNumbers, subChunksNumbers));
        }

        /// <summary>
        /// Preferred size of the response (in kilobytes).
        /// If 0 -- do not send this parameter.
        /// </summary>
        public int PreferredSize { get; set; }

        /// <summary>
        /// Collection of list requests
        /// </summary>
        internal List<DataListRequest> DataListRequests { get; private set; }

        /// <summary>
        /// Returns DataRequest string representation, which is than posted to API url.
        /// </summary>
        /// <returns></returns>
        public override string ToString()
        {
            var sb = new StringBuilder();
            if (PreferredSize > 0)
            {
                sb.Append(Constants.MARK_SIZE);
                sb.Append(PreferredSize);
                sb.Append(Constants.LF);
            }

            foreach (DataListRequest dataListRequest in DataListRequests)
            {
                sb.Append(dataListRequest.ToString());
                sb.Append(Constants.LF);
            }

            return sb.ToString();
        }
    }
}
